﻿#pragma once
// strcat.cpp: 定义控制台应用程序的入口点。
//
//#include "stdafx.h"
//#include "stdio.h"
#include <iostream>
using namespace std;


char* strcat_s(char *str1, char *str2) {

	int length1 = 0, length2 = 0;

	if (str1 != NULL) {
		while (str1[length1] != '\0')
		{
			length1++;
		}
	}
	else
	{
		length1 = 0;
	}

	if (str2 != NULL) {
		while (str2[length2] != '\0')
		{
			length2++;
		}
	}
	else
	{
		length2 = 0;
	}

	char *newstr = (char*)malloc(length1 + length2 + 1);

	int s1 = 0, s2 = 0, i = 0;
	
	if (length1 == 0)
	{
		if (length2 != 0)
		{
			while (str2[s2] != '\0')
			{
				newstr[i++] = str2[s2];
				s2++;
			}
		}
	}
	else
	{
		while (str1[s1] != '\0')
		{
			newstr[i++] = str1[s1];
			s1++;
		}

		if (length2 != 0)
		{
			while (str2[s2] != '\0')
			{
				newstr[i++] = str2[s2];
				s2++;
			}
		}
	}

	

	newstr[length1 + length2] = '\0';

	return newstr;

}
/*int main(int argc, _TCHAR* argv[])
{
//char *a1 = "Hello,Zhangqiao";
//char *a2 = "Hi!";
testing::strcat_s(&argc, argv);
return RUN_ALL_TESTS();


//cout << strcat_s("abc","def")<< endl;
//system("pause");

return 0;
}*/








